<template>
  <!-- 左侧二级菜单栏的组件封装 -->
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="toIndex"
      background-color="#fff"
      text-color="#000000"
      router>
      <el-menu-item v-for="(item, index) in itemList" :key="index" :index="item.path">
        <!-- 需要图标的在 item 对象中加上属性 icon -->
        <!-- <i :class="item.icon"></i> -->
        <span slot="title">{{ item.title }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  props: {
    itemList: {
      type: Array,
      default: () => []
    }
  },
  data(){
    return {

    }
  },
  computed: {
    toIndex(){  // 根据路径绑定到对应的二级菜单，防止页面刷新重新跳回第一个
      return this.$route.path.split('/')[2];
    }
  },
  methods:{
      
  },
}
</script>

<style lang="scss" scoped>
/* 左侧菜单栏定位和位置大小设定 */
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 52px;
  bottom: 0;
  overflow-y: scroll;

}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu {
  width: 220px;
  padding-top: 20px;
}
.sidebar > ul {
  height: 100%;
}

/* 左侧二级菜单项的样式 */
.el-menu-item{
  font-size: 14px !important;
}
.el-menu-item:hover{
  background: #Ffffff !important;
}

/* 左侧二级菜单选中时的样式 */
.el-menu-item.is-active {
  color: #2D4FA2 !important;
}
.el-menu-item span{
  text-align: center;
  display: inline-block;
  width: 144px;
  height: 44px;
  line-height: 44px;
  border-radius: 8px;
}
.el-menu-item:hover span,
.el-menu-item.is-active span{
  background: #eaf6ff;  
  color: #2D4FA2 !important;
}
.el-menu-item, .el-submenu__title {
  height: 50px !important;
  line-height: 50px !important;
}
</style>